/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.herenit.beijing.dh2011.security.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Obama
 */
@Entity
@Table(name = "SECURITY_PERMISSION")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SecurityPermission.findAll", query = "SELECT s FROM SecurityPermission s"),
    @NamedQuery(name = "SecurityPermission.findByPermissionId", query = "SELECT s FROM SecurityPermission s WHERE s.permissionId = :permissionId"),
    @NamedQuery(name = "SecurityPermission.findByOperationId", query = "SELECT s FROM SecurityPermission s WHERE s.operationId = :operationId"),
    @NamedQuery(name = "SecurityPermission.findByPermissionName", query = "SELECT s FROM SecurityPermission s WHERE s.permissionName = :permissionName"),
    @NamedQuery(name = "SecurityPermission.findByPermissionCode", query = "SELECT s FROM SecurityPermission s WHERE s.permissionCode = :permissionCode")})
public class SecurityPermission implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 32)
    @Column(name = "PERMISSION_ID")
    private String permissionId;
    @Size(max = 32)
    @Column(name = "OPERATION_ID")
    private String operationId;
    @Size(max = 20)
    @Column(name = "PERMISSION_NAME")
    private String permissionName;
    @Size(max = 20)
    @Column(name = "PERMISSION_CODE")
    private String permissionCode;
    @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "RESOURCE_ID")
    @ManyToOne
    private SecurityResource resourceId;
    @OneToMany(mappedBy = "permissionId")
    private List<SecurityPermissionAccount> securityPermissionAccountList;
    @OneToMany(mappedBy = "permissionId")
    private List<SecurityAccRolePermission> securityAccRolePermissionList;
    @OneToMany(mappedBy = "permissionId")
    private List<SecurityMenuPermission> securityMenuPermissionList;

    public SecurityPermission() {
    }

    public SecurityPermission(String permissionId) {
        this.permissionId = permissionId;
    }

    public String getPermissionId() {
        return permissionId;
    }

    public void setPermissionId(String permissionId) {
        this.permissionId = permissionId;
    }

    public String getOperationId() {
        return operationId;
    }

    public void setOperationId(String operationId) {
        this.operationId = operationId;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }

    public SecurityResource getResourceId() {
        return resourceId;
    }

    public void setResourceId(SecurityResource resourceId) {
        this.resourceId = resourceId;
    }

    @XmlTransient
    public List<SecurityPermissionAccount> getSecurityPermissionAccountList() {
        return securityPermissionAccountList;
    }

    public void setSecurityPermissionAccountList(List<SecurityPermissionAccount> securityPermissionAccountList) {
        this.securityPermissionAccountList = securityPermissionAccountList;
    }

    @XmlTransient
    public List<SecurityAccRolePermission> getSecurityAccRolePermissionList() {
        return securityAccRolePermissionList;
    }

    public void setSecurityAccRolePermissionList(List<SecurityAccRolePermission> securityAccRolePermissionList) {
        this.securityAccRolePermissionList = securityAccRolePermissionList;
    }

    @XmlTransient
    public List<SecurityMenuPermission> getSecurityMenuPermissionList() {
        return securityMenuPermissionList;
    }

    public void setSecurityMenuPermissionList(List<SecurityMenuPermission> securityMenuPermissionList) {
        this.securityMenuPermissionList = securityMenuPermissionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (permissionId != null ? permissionId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SecurityPermission)) {
            return false;
        }
        SecurityPermission other = (SecurityPermission) object;
        if ((this.permissionId == null && other.permissionId != null) || (this.permissionId != null && !this.permissionId.equals(other.permissionId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.herenit.beijing.dh2011.security.SecurityPermission[ permissionId=" + permissionId + " ]";
    }
    
}
